package com.shenjies88.practice.reactor.wrapper;

import com.shenjies88.practice.reactor.thread.SelectorThread;

import java.nio.channels.SocketChannel;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author shenjies88
 * @since 2022/12/7/23:21
 */
public class SelectorWrapper {

    private final LinkedBlockingQueue<SocketChannel> queue = new LinkedBlockingQueue<>();

    public void queue(SocketChannel socketChannel) {
        try {
            queue.put(socketChannel);
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.err.println("投递注册队列异常");
        }
    }

    public void init(int index) {
        var thread = new SelectorThread(queue, index);
        thread.start();
    }
}
